package fun.zhufn.oldcomm;

import fun.zhufn.oldcomm.model.bo.Old;
import fun.zhufn.oldcomm.model.service.OldManagerService;

import javax.swing.*;
import java.util.List;
import java.util.logging.Logger;

public class OldManagerController {
    private static final OldManagerController INSTANCE = new OldManagerController();
    private OldManagerController(){}
    public static OldManagerController getInstance() {
        return INSTANCE;
    }
    private static final Logger log = Logger.getLogger(OldManagerController.class.toString());

    public OldManagerService getOldSrv() {
        return oldSrv;
    }



    private final OldManagerService oldSrv = OldManagerService.getInstance();

    /**
     * @return 老人列表
     */
    public List<Old> getOldList() {
        return oldSrv.getOldList().getData();
    }

    /**
     * @param o 老人
     */
    public void addOld(Old o) {
        try {
            oldSrv.addOld(o);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * @param o 老人
     */
    public void editOld(Old o) {
        try {
            oldSrv.editOld(o);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * @param x 老人id
     */
    public void removeOld(int x) {
        try {
            if (!oldSrv.removeOld(x)) {
                JOptionPane.showMessageDialog(null, "删除失败！");
            }
        } catch(Exception e) {
            JOptionPane.showMessageDialog(null, "删除失败！" + e);
        }
    }

    /**
     * @param id 老人id
     * @param srv 服务人员账号
     */
    public void setOldSrv(int id, String srv) {
        try {
            oldSrv.setOldSrv(id, srv);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "修改服务人员失败！\n" + e);
        }
    }
}
